package com.qiantu.phone.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.qiantu.api.db.LLFloorDBManager;
import com.qiantu.api.entity.FloorBean;
import com.qiantu.api.entity.RoomBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.app.AppFragment;
import com.qiantu.phone.ui.activity.FloorGalleryActivity;
import com.qiantu.phone.ui.activity.RoomDeviceActivity;
import com.qiantu.phone.ui.activity.RoomGalleryActivity;
import com.qiantu.phone.ui.activity.RoomSettingActivity;
import com.qiantu.phone.ui.adapter.RoomGalleryAdapter;
import com.qiantu.phone.ui.adapter.RoomListBigAdapter;
import com.qiantu.phone.ui.adapter.RoomListSmallAdapter;

import java.util.List;
import java.util.Map;

public class RoomGalleryFragment extends AppFragment<AppActivity> {
    private RecyclerView recyclerView;

    private String selectPicUrl;

    private List<String> imageUrls;

    public static RoomGalleryFragment newInstance(List<String> imageUrls,String selectPicUrl) {
        RoomGalleryFragment fragment = new RoomGalleryFragment();
        Bundle bundle = new Bundle();
        fragment.setSelectPicUrl(selectPicUrl);
        fragment.setImageUrls(imageUrls);
        fragment.setArguments(bundle);
        return fragment;
    }

    public String getSelectPicUrl() {
        return selectPicUrl;
    }

    public void setSelectPicUrl(String selectPicUrl) {
        this.selectPicUrl = selectPicUrl;
    }

    public List<String> getImageUrls() {
        return imageUrls;
    }

    public void setImageUrls(List<String> imageUrls) {
        this.imageUrls = imageUrls;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_room_gallery;
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.gallery_recycler_view);
        initRecyclerView();

    }

    @Override
    protected void initData() {

    }

    private void initRecyclerView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        RoomGalleryAdapter roomGalleryAdapter = new RoomGalleryAdapter(getContext());
        roomGalleryAdapter.setSelected(selectPicUrl);
        recyclerView.setAdapter(roomGalleryAdapter);
        roomGalleryAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
                String imageUrl = roomGalleryAdapter.getData().get(position);
                roomGalleryAdapter.setSelected(imageUrl);
                ((RoomGalleryActivity) getActivity()).setSelectPicUrl(imageUrl);
            }
        });
        roomGalleryAdapter.setData(imageUrls);
    }
}
